/**********************************************************************
 * FILE : Queuepool.java
 * CREATE DATE : 2011-12-6
 * DESCRIPTION :
 *		
 *      
 * CHANGE HISTORY LOG
 *---------------------------------------------------------------------
 * NO.|    DATE    |     NAME     |     REASON     | DESCRIPTION
 *---------------------------------------------------------------------
 * 1  | 2011-12-6 |  Sting  |    草创版本
 *---------------------------------------------------------------------              
 **********************************************************************
 */
package com.sgm.de.benchmark.act;

import java.util.LinkedList;
import java.util.Queue;

import com.sgm.de.benchmark.ProcessContext;

/**
 * @author Sting
 * TODO 主要作用:
 *		注意事项:
 */
public class Queuepool  extends AbstractAct {

    /*
     * (non-Javadoc)
     * @see com.sgm.de.benchmark.act.AbstractAct#exec(com.sgm.de.benchmark.ProcessContext)
     */
    @Override
    public void exec(ProcessContext ctx) throws Exception {
        String queuename = args[0].toString();
        if (queuename != null && queuename.indexOf("?") > -1) {// 第一个参数有问号(?),则为模式匹配
            int from = Integer.valueOf(args[1].toString());
            int to = Integer.valueOf(args[2].toString());
            if (ctx.queuePool == null) {
                ctx.queuePool = new LinkedList<String>();
            }
            Queue<String> q = ctx.queuePool;
            for (int i = from; i <= to; i++) {
                q.add(queuename.replace("?", String.valueOf(i)).trim());
            }
        } else {// 否则为枚举名称
            if (ctx.queuePool == null) {
                ctx.queuePool = new LinkedList<String>();
            }
            for (Object obj : args) {
                ctx.queuePool.add(obj.toString().trim());
            }
        }

    }
}
